import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Choice;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.ActionListener;



import javax.swing.ButtonGroup;
import javax.swing.JRadioButton;



/**
 * @author 
 * Yannic Remmet			196983
 * Tobias Trabelsi			197112
 * Anna-Katharina Wickert	197122
 */
public class Menu extends Frame {

	private static final long serialVersionUID = 5237335232850181080L;
	private CircleSquare can;
	private Button bExit, bClear,bDraw;
	private ButtonGroup bgCirSq, bgFillUnf;
	private JRadioButton rbCircle, rbSquare, rbFill, rbUnfill;
	private TextField tfX,tfY, tfZ;
	private Panel pXYZ;
	private Choice cColor;
	private Color[] colAr = new Color[] {Color.black, Color.blue, Color.cyan, Color.DARK_GRAY, Color.gray, Color.lightGray, Color.magenta, Color.orange};
	
	public Menu(CircleSquare c){
		super("Menu");
		can = c;
         
         bExit = new Button("Exit");
         bClear = new Button("Clear");
         bDraw = new Button("Draw");
         
         tfX = new TextField("1", 3);
         tfY = new TextField("1", 3);
         tfZ = new TextField("50", 3);
  
       
        
        cColor = new Choice();
        cColor.add("Black");
        cColor.add("Blue");
        cColor.add("Cyan");
        cColor.add("Dark Gray");
        cColor.add("Gray");
        cColor.add("Light Gray");
        cColor.add("Magenta");
        cColor.add("Orange");
        cColor.select("Magenta");
        
        
        rbCircle = new JRadioButton("Circle");
        rbCircle.addActionListener(new ActionListener() {
       	 public void actionPerformed(ActionEvent arg0){
       	 }
        });
 
        rbCircle.setActionCommand("cir");
        rbCircle.setSelected(true);
        rbSquare = new JRadioButton("Sqaure");
        rbSquare.addActionListener(new ActionListener(){
       	 public void actionPerformed(ActionEvent arg0){
       	 }
        });
        rbSquare.setActionCommand("sq");
        bgCirSq = new ButtonGroup();
        bgCirSq.add(rbCircle);
        bgCirSq.add(rbSquare);
        
        
        rbFill = new JRadioButton("Fill");
        rbFill.addActionListener(new ActionListener(){
       	 public void actionPerformed(ActionEvent arg0){
       	 }
        });
        rbFill.setActionCommand("fill");
        rbFill.setSelected(true);
        rbUnfill = new JRadioButton("Unfill");
        rbUnfill.addActionListener(new ActionListener(){
       	 public void actionPerformed(ActionEvent arg0){
       	 }
        });
        rbUnfill.setActionCommand("unfill");
        bgFillUnf = new ButtonGroup();
        bgFillUnf.add(rbFill);
        bgFillUnf.add(rbUnfill);
        

       
       Panel choicer = new Panel();
       choicer.add(rbFill);
       choicer.add(rbUnfill);
       choicer.add(rbCircle);
       choicer.add(rbSquare);
       choicer.setVisible(true);
       
       Panel buttons = new Panel();
       buttons.add(bDraw);
       buttons.add(bClear);
       buttons.add(bExit);
       buttons.setVisible(true);
       
       Panel text = new Panel();
       text.add(tfX, tfY);
       text.add(tfZ);
       text.setVisible(true);
        
         bExit.addActionListener(new ActionListener() {
        	 public void actionPerformed(ActionEvent arg0){
        		 System.exit(0);
        	 }
         });
         bClear.addActionListener(new ActionListener() {
        	 public void actionPerformed(ActionEvent arg0){
        		 can.repaint();
        	 }
         });
         
         bDraw.addActionListener(new ActionListener() {
        	 public void actionPerformed(ActionEvent arg0){
        		try{
        		int z = Integer.parseInt(tfZ.getText());
 		    	int x = Integer.parseInt(tfX.getText());
 		    	int y = Integer.parseInt(tfY.getText());
 		    	
 		    	Color c = colAr[cColor.getSelectedIndex()];
 		    	
 				if (bgCirSq.getSelection().getActionCommand().equals("cir")){
 					if (bgFillUnf.getSelection().getActionCommand().equals("fill")){
 						can.fillCircle(x, y, z, c);
 					}
 					else {
 						can.drawCircle(x, y, z,c);
 					}
 				}
 				else{
 					if (bgFillUnf.getSelection().getActionCommand().equals("fill")){
 						can.fillSquare(x, y, z, c);
 					}
 					else{
 						can.drawSquare(x, y, z, c);
 					}
 						
 					
 				}
 			}
        	 
 			catch (NumberFormatException ex){
 				// Dialog -> Owner: Window, Frame, Dialog!
        } }
         });
         
         pXYZ = new Panel();
         pXYZ.add(tfX);
         pXYZ.add(tfY);
         pXYZ.add(tfZ);
        
        setLayout(new BorderLayout());
        add(BorderLayout.SOUTH, cColor);
        add(BorderLayout.CENTER, choicer);
        add(BorderLayout.NORTH, buttons );
        add(BorderLayout.EAST, pXYZ);
        
        setVisible(true);
        setSize(200,200);
        addWindowListener(new WindowAdapter() {
     	   public void windowClosing(WindowEvent e){
     		   System.exit(0);
     	   }
        });
       
   
 }
 
 
}
